package com.ishansong.ticket.exception;


import org.springframework.core.NestedCheckedException;
 
/**
 * 服务异常
 *
 * @author hongtaozhang
 */
public class ServiceException extends NestedCheckedException {

    private static final long serialVersionUID = -319844289653018942L;

    /**
     * 默认为-1，表示未知错误.
     */
    private int errorCode = -1;


    /**
     * 返回错误编码, 默认为-1表示未知错误.
     *
     * @return 错误编码
     */
    public int getErrorCode() {
        return this.errorCode;
    }

    /**
     * Constructs a new exception with the specified detail message.  The
     * cause is not initialized, and may subsequently be initialized by
     * a call to {@link #initCause}.
     *
     * @param errorCode the error code.
     */
    public ServiceException(int errorCode) {
        super("error code is:" + errorCode);
        this.errorCode = errorCode;
    }

    public ServiceException(int errorCode, String msg) {
        super(msg);
        this.errorCode = errorCode;
    }

    /**
     * 服务异常构造函数.
     *
     * @param errorCode 异常编码
     */
    public ServiceException(int errorCode, Object... params) {
        this(errorCode, null, (Object[]) null);
    }

    /**
     * 服务异常构造函数.
     *
     * @param errorCode 异常编码
     * @param cause     异常
     */
    public ServiceException(int errorCode, Throwable cause, Object... params) {
        this(cause);
        this.errorCode = errorCode;
    }


    /**
     * 服务异常构造函数.
     *
     * @param message 异常的信息.
     */
    public ServiceException(String message) {
        super(message);
    }

    /**
     * 服务异常构造函数.
     *
     * @param cause 异常
     */
    public ServiceException(Throwable cause) {
        this(cause.getMessage(), cause);
    }

    /**
     * 服务异常构造函数.
     *
     * @param message 异常的信息.
     * @param cause   异常
     */
    public ServiceException(String message, Throwable cause) {
        super(message, cause);
    }

}
